//定义小仓库
import { defineStore } from "pinia";
import { reqroomItem, reqRoomList, reqhistoryList } from '../api/room/index'
let useRoomstore = defineStore('roomstore', {
    state: () => ({
        roomList: [],
        roomItemdata: [],
        planName: '',//名字
        cover: '',//头像
        contentId: '',//点击二级跳转的id
        planId: '',//点击一级跳转的id
        historyList:[]
    }),
    actions: {
        // 点击header组件导航栏练习室触发的函数
        async getRoomList() {
            const result = await reqRoomList()
            // console.log(result);
            if (result.status == 200) {
                this.roomList = result.data.content
            }
        },
        // 点击每一条数据出来的
        async torommItem(planId) {
            const result = await reqroomItem(planId)
            if (planId) {
                // this.planId=planId
                const a = this.roomList.find(item => item.id === planId)
                this.planName = a.planName
                // this.cover = a.cover
            }
            // console.log(result);
            if (result.status) {
                this.roomItemdata = result.data.content
            }
        },

        // 点击历史按钮
        async handlerhistory() {
            const result = await reqhistoryList()
            console.log(result);
            if (result.status == 200) {
                this.historyList = result.data.content
              this.historyList.map(item=>item.ischecked =false)
              
            }
        }
    },
    getters:{
        cover(state){
            return this.historyList.momentBackup? this.historyList.momentBackup.cover[0] :{}
        }
    }
})
export default useRoomstore